/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2024-10-12
 * Time: 19:12
 */
public class test2 {
    /*
    LeetCode1137 第N个泰波那契数 T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
    第一道动态规划（斐波那契数模型）
     */
    public int tribonacci(int n) {
        if(n==0 || n==1){
            return n;
        }
        if(n==2){
            return 1;
        }
        int [] dp = new int[n+1];
        dp[0]=0;
        dp[1] = dp[2] = 1;
        for(int i =3;i<=n;i++){
            dp[i] = dp[i-3]+ dp[i-2] + dp[i-1];
        }
        return dp[n];
    }

}
